import request from '@/utils/request.js'

/**
 * 获取验证码
 */
export function getLoginCheckCode() {
  return request.get('/user/captcha')
}

/**
 * 登录
 * @param user
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function login(user) {
  return request.post('/login/', user)
}

/**
 * 修改用户基本信息
 * @param baseInfo
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function editUserInfo(baseInfo) {
  return request.put('/user/info', baseInfo)
}

/**
 * 修改用户密码
 * @param oldPassword
 * @param newPassword
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function editUserPassword(oldPassword, newPassword) {
  return request.put(`/user/reset/password/${oldPassword}/${newPassword}`)
}

/**
 * 登出
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function loginOut() {
  return request.post('/user/logout')
}

/**
 * 获取个人信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getUserInfo() {
  return request.get('/user/info')
}

/**
 * 分页获取用户数据
 * @param page
 * @param size
 * @param searchParams
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getUserListInfo(page, size, searchParams) {
  return request.get(`/user/list/${page}/${size}`, {
    params: {
      userName: searchParams?.userName,
      status: searchParams?.status,
      phonenumber: searchParams?.phonenumber,
      startTime: searchParams?.startTime,
      endTime: searchParams?.endTime
    }
  })
}

/**
 * 删除用户信息
 * @param userId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function removeUserByUserId(userId) {
  return request.delete(`/user/remove/${userId}`)
}

/**
 * 批量删除用户信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 * @param ids
 */
export function removeBatchUserByUserIds(ids) {
  return request.delete('/user/batch', {
    ids: ids
  })
}

/**
 * 重置用户列表密码
 * @param userId
 * @param password
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function resetPassword(userId) {
  return request.put(`/user/reset/${userId}`)
}

/**
 * 新增用户
 * @param userInfo
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function addUserInfo(userInfo) {
  return request.post('/user/add', userInfo)
}

/**
 * 编辑用户信息
 * @param userInfo
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function editUser(userInfo) {
  return request.put('/user/edit', userInfo)
}

//验证ECP登录
export function loginEcp(param) {
  return request.post('/api/ecp/login/setTokenURL', param)
}
